//时间拼接函数
let years = new Date().getFullYear();
let mon = new Date().getMonth() + 1;
let date = new Date().getDate();
let start = new Date(`${years}-${mon}-${date}`).getTime();
// const crypto = require('crypto')


module.exports = {
    //加密
    md5: function (str) {
        // return crypto.createHash('md5').update(str).digest('hex')
    },
    sha1: function (str) {
        return crypto.createHash('sha1').update(str).digest('hex')
    },

    add0:function(m) { return m < 10 ? '0' + m : m },

    stampChangeFormat:function (str) {
        let year = new Date(str).getFullYear();
        let mon = new Date(str).getMonth() + 1;
        let date = new Date(str).getDate();
        let hou = new Date(str).getHours();
        let min = new Date(str).getMinutes();
        let sec = new Date(str).getSeconds();
        return `${year}-${this.add0(mon)}-${this.add0(date)} ${this.add0(hou)}:${this.add0(min)}:${this.add0(sec)}`;
    },
    stampChangeFormatSecond:function (str) {
        let year = new Date(str).getFullYear();
        let mon = new Date(str).getMonth() + 1;
        let date = new Date(str).getDate();
        return `${year}-${this.add0(mon)}-${this.add0(date)}`;
    },
    stampChangehHonurs:function (str) {
        let hou = new Date(str).getHours();
        let min = new Date(str).getMinutes();
        let sec = new Date(str).getSeconds();
        return `${this.add0(hou)}:${this.add0(min)}:${this.add0(sec)}`;
    },
    //最新时间
    newStampChangeFormat: function() {
        let year = new Date().getFullYear();
        let mon = new Date().getMonth() + 1;
        let date = new Date().getDate();
        let hou = new Date().getHours();
        let min = new Date().getMinutes();
        let sec = new Date().getSeconds();
        return `${year}-${mon > 9? mon: "0" + mon}-${date > 9? date: "0" + date} ${hou > 9? hou: '0' + hou}:${min > 9? min: "0" + min}:${sec > 9? sec: "0" + sec}`;
    },
    timestampToDate(timestamp) {  
        // 确保时间戳是毫秒级的，如果不是，乘以1000  
        if (typeof timestamp === 'string' && timestamp.length <= 10) {  
            timestamp = parseInt(timestamp) * 1000;  
        }  
      
        const date = new Date(timestamp);  
        const year = date.getFullYear();  
        const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份是从0开始的，所以需要+1  
        const day = String(date.getDate()).padStart(2, '0');  
      
        return `${year}-${month}-${day}`;  
    }

   
    
}